package com.di.base.interceptor;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import io.seata.core.context.RootContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FeignSeataInterceptor {

    @Bean
    public RequestInterceptor seataFeignRequestInterceptor() {
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate template) {
                String xid = RootContext.getXID();
                if (xid != null) {
                    template.header(RootContext.KEY_XID, xid);
                }
            }
        };
    }
}
